@extends('backstage.layout.master')
@section('title', '优惠劵发放')
@section('style')
<meta name="_token" content="{{csrf_token()}}"/>
<link rel="stylesheet" href="assets/css/jquery-ui-1.10.3.custom.min.css"/>
<link rel="stylesheet" href="assets/css/chosen.css"/>
<link rel="stylesheet" href="assets/css/datepicker.css"/>
<link rel="stylesheet" href="assets/css/bootstrap-timepicker.css"/>
<link rel="stylesheet" href="assets/css/daterangepicker.css"/>
<link rel="stylesheet" href="assets/css/colorpicker.css"/>
<!-- fonts -->
@stop
@section('script')
<script src="js/jquery-migrate-1.2.1.min.js"></script>
@section('script')
	<script type="text/javascript">
		$(function () {
			var channel_id=$("#channel_id").val();
			$("#generate").click(function(){
				$.ajax({
					type: "get",
					url: "/backstage/coupons/generatexls",
					data: {"channel_id": channel_id},
					success: function (msg) {
						if (msg.state == "M00000") {
							$("#download").attr("href",msg.url);
							swal({
								title: "生成成功",
								text: "",
								type: "success",
								timer:2000
							});
						}else{
							swal({
								title: msg.message,
								text: "",
								type: "error",
								timer:2000
							});
						}
					},
					error: function () {
						swal({
							title: "系统繁忙！",
							text: "",
							type: "error",
							timer:2000
						});
					}
				});
			});
			$("#download_coupon").click(function () {
				var url =$("#download").attr("href");
				if(url=="javascript:void(0);"){
					swal({
						title:"请先生成Excel表格",
						text: "",
						type: "error",
						timer:2000
					});
				}else{
					downloadFile(url);
				}
			});
            $("#download_qr_zip").click(function () {
                var channel_id=$("#channel_id").val();
                if(channel_id==''||channel_id==null||channel_id==undefined){
                    return false;
                }
                console.log('二维码下载');
                $.ajax({
                    type: "post",
                    url: "/backstage/coupons/coupons-qr-img",
                    data: {"id": channel_id},
                    success: function (msg) {
                        if (msg.state == 1) {
                            swal({
                                title: "打包成功",
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            var zip_url=msg.zip_url;
                            downloadFile(zip_url);
                        }else{
                            swal({
                                title:msg.message,
                                text: "",
                                type: "error",
                                timer:2000
                            });
                        }
                    },
                    error: function () {
                        swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });
            });
		});

		/**
		 * 下载Excel
		 * @param url
         */
		function downloadFile(url){
			if(url==null||url==undefined||url==''){
                console.log('下载地址为空');
				return;
			}
			var iframe = document.createElement("iframe");
			document.body.appendChild(iframe);
			iframe.src =url;
			setTimeout(function(){
				document.body.removeChild(iframe);
			},3000);
		}
	</script>
@stop

@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/coupons/couponslist">优惠劵</a>
            </li>
            <li>
                优惠劵查询修改
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>
	
    <div class="page-content" id="load">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                  <h1>
                        优惠劵
                        <small>
                        <i class="icon-double-angle-right"></i>
                        优惠劵发放
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                    <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
                        
							
							<div class="space-4"></div>
							<div style="width:600px; float:left;">
								<div class="table-responsive">
									<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<tr>
												<td>
													优惠劵编号
												</td>
												<td>
													<input type="text" id="channel_id" style="width:190px;"  class="col-xs-10 col-sm-5" value="{{isset($channel->channel_id)?$channel->channel_id:''}}" readonly="true"/>
												</td>
											</tr>
											<tr class="" data-tr-id="{{$channel->channel_id}}">
												<td>优惠劵金额</td>
												<td>
													<input type="text" id="price" style="width:190px;" value="{{isset($channel->price)?$channel->price:''}}" class="col-xs-10 col-sm-5" readonly="true"/>
												</td>
											</tr>
											<tr>
												<td>
													总数
												</td>
												<td>
													<input type="text" id="coupon_num" style="width:190px;" value="{{isset($channel->num)?$channel->num:''}}" class="col-xs-10 col-sm-5" readonly="true"/>
												</td>
											</tr>
										<tr>
											<td>
												名称
											</td>
											<td>
												<input type="text"  style="width:190px;" value="{{isset($channel->name)?$channel->name:''}}" class="col-xs-10 col-sm-5" readonly="true"/>
											</td>
										</tr>
											<tr>
												<td>
													开始时间
												</td>
												<td>
													<input type="text" id="began_time" style="width:190px;" class="col-xs-10 col-sm-5" value="{{isset($channel->begin_time)?date('Y-m-d H:i:s',$channel->begin_time):''}}" readonly="true"/>
												</td>
											</tr>
											<tr>
												<td>
													结束时间
												</td>
												<td>
													<input type="text" id="end_time" style="width:190px;" value="{{isset($channel->end_time)?date('Y-m-d H:i:s',$channel->end_time):''}}" class="col-xs-10 col-sm-5" readonly="true"/>
												</td>
											</tr>
											<tr>
												<td>
													简介
												</td>
												<td>
													<textarea class="form-control" name="intro" id="intro" readonly="true">{{isset($channel->intro)?$channel->intro:''}}</textarea>
												</td>
											</tr>
									</table>
								 </div>
                            <div class="clearfix form-actions" >
                                <div class="col-md-offset-3 col-md-9">
                                    <button id="generate" class="btn generate" type="button">
                                        <i class="icon-bar-chart bigger-110"></i>
                                        生成Excel
                                    </button>
                                    <button id="download_coupon" class="btn btn-info" type="button">
                                        <i class="icon-download-alt bigger-110"></i>
										<a href="javascript:void(0);" id="download">下载Excel</a>
                                    </button>
                                    <button id="download_qr_zip" class="btn btn-info" type="button">
                                        <i class="icon-download-alt bigger-110"></i>
                                        <a href="javascript:void(0);" id="download_zip">下载二维码</a>
                                    </button>
                                </div>
                            </div>
							</div>
                        </form>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
		</div>
@stop
